const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const FriendSchema = new Schema({
    // from: Schema.Types.ObjectId,
    // to: Schema.Types.ObjectId,
    // 只要添加了，两个人就互为好友
    from: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        // ref 表示关联 User, 被关联的model的type必须是ObjectId，Number，String 和 Buffer 才有效
    },
    to: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },

    // from 与 to互为好友
    create_time: {
        type: Date,
        default: Date.now
    }
})

const Friend = mongoose.model('Friend', FriendSchema);

module.exports = Friend;